package com.infoland.afanmall.model.youXuan.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.LogKit;
import com.infoland.afanmall.base.util.StatusBarKit;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.model.youXuan.entity.FaXianEntity;
import com.wyj.floatlayout.FlowLayout;
import com.wyj.floatlayout.TagAdapter;
import com.wyj.floatlayout.TagFlowLayout;
import com.wyj.floatlayout.TagView;

import java.util.ArrayList;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author 王永吉
 * @date 2018/7/16 15:22
 */
public class SearchContentActivity extends AppCompatActivity {

    @BindView(R.id.ys_search)
    EditText ysSearch;
    @BindView(R.id.ys_title)
    LinearLayout ysTitle;
    @BindView(R.id.left_fl)
    TagFlowLayout leftFl;
    ArrayList<FaXianEntity> faxianList;
    @BindView(R.id.bao_zhuang)
    TagFlowLayout baoZhuang;
    @BindView(R.id.menu)
    RelativeLayout menu;
    @BindView(R.id.drab_layout)
    DrawerLayout drabLayout;
    @BindView(R.id.shai_xuan)
    RadioButton shaiXuan;


    private int getLayout() {
        return R.layout.search_content_activity;

    }

    //入口
    private void initData() {
        shaiXuan.setOnClickListener(v -> {
            drabLayout.openDrawer(Gravity.RIGHT);
        });
        setDiQu();
        setBaoZhuang();
    }

    //设置地区
    private void setDiQu() {
        faxianList = new ArrayList<>();
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        leftFl.setAdapter(new TagAdapter<FaXianEntity>(faxianList) {
            @Override
            public View getView(FlowLayout parent, int position, FaXianEntity faXianEntity) {
                View inflate = getLayoutInflater().inflate(R.layout.search_item_t_yuan, leftFl, false);
                TextView viewById = inflate.findViewById(R.id.text);
                viewById.setText(new Random().nextInt(100000) + "");
                return inflate;
            }
        });

        leftFl.setOnTagClickListener((view, position, parent) -> {
            TagView tagView = (TagView) view;
            LogKit.E("aaaa ---->   ", "  " + position);

//                tagView.setVisibility(View.GONE);
//            tagView.setChecked(false);
            return true;
        });

        leftFl.setOnSelectListener(selectPosSet -> {
            LogKit.E("leftFl  selectPosSet ---->   ", "  " + selectPosSet);
        });
    }

    //设置地区
    private void setBaoZhuang() {
        faxianList = new ArrayList<>();
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        faxianList.add(new FaXianEntity());
        baoZhuang.setAdapter(new TagAdapter<FaXianEntity>(faxianList) {
            @Override
            public View getView(FlowLayout parent, int position, FaXianEntity faXianEntity) {
                View inflate = getLayoutInflater().inflate(R.layout.search_item_t_yuan, baoZhuang, false);
                TextView viewById = inflate.findViewById(R.id.text);
                viewById.setText(new Random().nextInt(100000) + "");
                return inflate;
            }
        });

        baoZhuang.setOnTagClickListener((view, position, parent) -> {
            TagView tagView = (TagView) view;
            LogKit.E("aaaa ---->   ", "  " + position);
//                tagView.setVisibility(View.GONE);
//            tagView.setChecked(false);
            return true;
        });
        baoZhuang.setOnSelectListener(selectPosSet -> {
            LogKit.E("baoZhuang  selectPosSet ---->   ", "  " + selectPosSet);
        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());
        ButterKnife.bind(this);
        ToolsKit.setEditHide(ysSearch);
        StatusBarKit.immersiveBlackTitleText(this, ysTitle);
        StatusBarKit.setPaddingSmart(this, menu);
        drabLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        drabLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                LogKit.E("aaaa ---->   ", "侧拉菜单打开了  ");

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                LogKit.E("aaaa ---->   ", "侧拉菜单关闭了  ");
            }

            @Override
            public void onDrawerStateChanged(int newState) {
            }
        });


        initData();
    }

    @Override
    public void onBackPressed() {
        if (drabLayout.isDrawerOpen(Gravity.RIGHT)) {
            drabLayout.closeDrawer(Gravity.RIGHT);
        } else {
            super.onBackPressed();
        }
    }
    @Override
    protected void onDestroy() {
        ToolsKit.deleteOKHttp(this);
        super.onDestroy();
    }
}
